package com.xyd.servlet;

import com.xyd.service.CommentService;
import com.xyd.service.impl.CommentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 86186
 */
@WebServlet("/CommentDelServlet")
public class CommentDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String ecId_str=request.getParameter("ecId");
        long ecId=Long.parseLong(ecId_str);
        CommentService comm=new CommentServiceImpl();
        Boolean flag=comm.delComment(ecId);

        if (flag){
            request.getRequestDispatcher("CommentServlet?pageIndex=0").forward(request,response);
        }
        else {
            System.out.println("删除失败");
            response.sendRedirect("manage/guestbook.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
